/*
 * @Author: LBH 1336709799@qq.com
 * @Date: 2024-10-28 12:17:33
 * @LastEditors: LBH 1336709799@qq.com
 * @LastEditTime: 2024-11-02 09:04:33
 * @FilePath: \enjoy_plus_three\lib\router\index.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:enjoy_plus_three/pages/house/building_list.dart';
import 'package:enjoy_plus_three/pages/house/house_form.dart';
import 'package:enjoy_plus_three/pages/house/house_list.dart';
import 'package:enjoy_plus_three/pages/house/location_list.dart';
import 'package:enjoy_plus_three/pages/house/room_list.dart';
import 'package:enjoy_plus_three/pages/login/index.dart';
import 'package:enjoy_plus_three/pages/notFound/index.dart';
import 'package:enjoy_plus_three/pages/notice/index.dart';
import 'package:enjoy_plus_three/pages/profile/index.dart';
import 'package:enjoy_plus_three/pages/tab_bar_page.dart';
import 'package:enjoy_plus_three/utils/token.dart';
import 'package:flutter/material.dart';

class RouterManager{
  static Map<String,WidgetBuilder>routes = {
    '/': (context) => const TabBarPage(),
      '/detail': (context) => const NoticeDetail(),
      '/login':(context) => const LoginPage()
  };
  static Route<dynamic> generateRoute(RouteSettings settings){
    final tokenManager = TokenManager();
      final token = tokenManager.getToken() ?? '';
      // settings.name访问路径
      if(token.isEmpty && settings.name != '/login'){
        return MaterialPageRoute(builder: (context) => const LoginPage());
      }
      // 执行到这里的时候,token是存在的
      if(settings.name == '/profile'){
        return MaterialPageRoute(builder: (context) => ProfilePage(userInfo:settings.arguments as Map));
      }
      if (settings.name == '/house_list') {
        return MaterialPageRoute(
            builder: (context) =>
                const HouseList());
      }
      if (settings.name == '/location_list') {
        return MaterialPageRoute(builder: (context) => const LocationList());
      }
      if (settings.name == '/building_list') {
        return MaterialPageRoute(builder: (context) =>  BuildingList(point: (settings.arguments as Map)['point']));
      }
       if (settings.name == '/room_list') {
        Map temp = settings.arguments as Map;
        return MaterialPageRoute(builder: (context) =>RoomList(
          point: temp['point'],
          building: temp['building'],
        ));
      }
      if (settings.name == '/house_form') {
      return MaterialPageRoute(
      builder: (context) => HouseForm(
          params: settings.arguments as Map,
      )
      );
      }
      return MaterialPageRoute(builder: (context) => const NotFound());
      
  }
}